package hibernate;


import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import entities.*;

public class HibernateUtil 
	{
	    private static SessionFactory sessionFactory;
	    
	    public static SessionFactory getSessionFactory()
	    {
	        try
	        {
	        	if(sessionFactory == null)
	    		{
	        	
		        	AnnotationConfiguration config = new AnnotationConfiguration();
		        	
		        	config.addAnnotatedClass(Cliente.class);
		        	config.addAnnotatedClass(Cotizacion.class); 
		        	config.addAnnotatedClass(Empleado.class);
		        	config.addAnnotatedClass(Presupuesto.class);
		       	 	config.addAnnotatedClass(ProServ.class);
		        	config.addAnnotatedClass(Proveedor.class);
		        	config.addAnnotatedClass(Servicio.class);
		        	config.addAnnotatedClass(TipoEvento.class);
		        	
		            return sessionFactory = config.buildSessionFactory();
	    		}else{
	    			return sessionFactory;
	    		}
	        }
	        catch (Throwable ex)
	        {
	            System.err.println("Initial SessionFactory creation failed." + ex);
	            throw new ExceptionInInitializerError(ex);
	        }
	    }
	 
	}
